// 数据概览页面
const app = getApp();
const request = require('../../../utils/request.js').request;

Page({
  data: {
    loading: true,
    stats: {
      orders: {},
      users: {},
      scenicAreas: {}
    }
  },

  onLoad: function (options) {
    this.loadDashboardData();
  },

  onPullDownRefresh: function () {
    this.loadDashboardData();
  },

  // 加载仪表盘数据
  loadDashboardData: function () {
    this.setData({ loading: true });
    
    request({
      url: '/api/stats/dashboard',
      method: 'GET',
      success: (res) => {
        if (res.code === 0) {
          this.setData({
            stats: res.data,
            loading: false
          });
        } else {
          wx.showToast({
            title: res.msg || '获取数据失败',
            icon: 'none'
          });
          this.setData({ loading: false });
        }
      },
      fail: () => {
        wx.showToast({
          title: '网络错误',
          icon: 'none'
        });
        this.setData({ loading: false });
      },
      complete: () => {
        wx.stopPullDownRefresh();
      }
    });
  },

  // 导航到详细统计页面
  navigateToStat: function (e) {
    const type = e.currentTarget.dataset.type;
    if (type === 'order') {
      wx.navigateTo({
        url: '/pages/admin/order/order'
      });
    } else if (type === 'user') {
      wx.navigateTo({
        url: '/pages/admin/user/user'
      });
    } else if (type === 'scenic') {
      wx.navigateTo({
        url: '/pages/admin/scenic/scenic'
      });
    }
  }
}) 